package com.example.zg3_park.RepairOrder

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil.ItemCallback
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import androidx.viewpager.widget.PagerAdapter
import com.example.lib_base.entity.RepairOrderEntityItem
import com.example.zg3_park.R
import com.example.zg3_park.databinding.ItemRepairBinding

class RepairAdapter:PagingDataAdapter<RepairOrderEntityItem, RepairAdapter.RepairViewHolder>(diff) {

    companion object{
        val diff = object :ItemCallback<RepairOrderEntityItem>() {
            override fun areItemsTheSame(
                oldItem: RepairOrderEntityItem,
                newItem: RepairOrderEntityItem
            ): Boolean {
                return oldItem == newItem
            }

            override fun areContentsTheSame(
                oldItem: RepairOrderEntityItem,
                newItem: RepairOrderEntityItem
            ): Boolean {
                return oldItem.id == newItem.id
            }

        }
    }

    class RepairViewHolder(view: View):ViewHolder(view) {
        val binding = DataBindingUtil.bind<ItemRepairBinding>(view)
    }

    override fun onBindViewHolder(holder: RepairViewHolder, position: Int) {
        val item = getItem(position)
        holder.binding?.repair = item

        holder.binding?.tvStatus?.apply {
            when(item?.processingStatus) {
                "待处理" -> {
                    setBackgroundResource(R.drawable.color_weihu)

                }
            }
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RepairViewHolder {
        val view =
            LayoutInflater.from(parent.context).inflate(R.layout.item_repair, parent, false)
        return RepairViewHolder(view)
    }


}